if (inweo.get("inweo.widgets.tabs") != true) {
	inweo.set("inweo.widgets.tabs", true);
	inweo.widgets.tabs = inweo.core.widget.extend({
		initialize: function() {
			this.widget = new Element("div");
			this.widget.addClass("tabs");
			this.registerWidget("tabs");

			this.header = new Element("ul");
			this.header.addClass("tabsHeader");
			this.header.addClass("widgetUnselectable");
			this.header.injectInside(this.widget);

			this.container = new Element("div");
			this.container.addClass("tabsContainer");
			this.container.injectInside(this.widget);
		}
	});
	inweo.set("inweo.widgets.tabItem", true);
	inweo.widgets.tabItem = inweo.core.widget.extend({
		__select: [],
		__close: [],
		initialize: function(tabs) {
			var self = this;
			this.tabs = tabs;
			inweo.require("label");

			this.widget = new Element("div");
			this.widget.addClass("tabItem");
			this.widget.injectInside(tabs.container);
			this.registerWidget("tabItem");

			this.tab = new Element("li");
			this.tab.setProperty("tab", this.id);
			this.tab.addClass("tab");
			this.tab.injectInside(tabs.header);
			new inweo.core.event(this.tab).addEvent("mousedown", function() {
				self.select();
			});
			
			this.image = new Element("img");
			this.image.injectInside(this.tab);
			
			this.label = new inweo.widgets.label();
			this.label.widget.injectInside(this.tab);

			this.closeImage = new Element("img");
			this.closeImage.addClass("tabCloseImage");
			this.closeImage.injectInside(this.tab);
			this.closeImage.setStyle("display", "none");
			new inweo.core.event(this.closeImage).addEvent("mousedown", function() {
				self.close();
			});

			if (tabs.header.getElements("li").length == 1) {
				this.select();
			}
		},
		closePicture: function(src) {
			if (src) {
				this.closeImage.setStyle("display", "inline");
				this.closeImage.src = src;
			} else {
				return this.closeImage.src;
			}
		},
		picture: function(src) {
			if (src) {
				this.image.src = src;
			} else {
				return this.image.src;
			}
		},
		text: function(string) {
			return this.label.text(string);
		},
		pack: function(child) {
			child.__pack(this.widget);
		},
		onClose: function(fn) {
			this.__close.push(fn);
		},
		close: function() {
			// select another tab
			this.tab.remove();
			this.remove()
			inweo.execute(this.__select, this);
		},
		onSelect: function(fn) {
			// this.__select[length] = fn;
			this.__select.push(fn);
		},
		select: function() {
			var selected = this.tabs.header.getElement(".tabSelected");
			if ($type(selected) == "element") {
				selected.removeClass("tabSelected");
			}
			this.tab.addClass("tabSelected");
			selected = this.tabs.container.getElement(".tabItemSelected");
			if ($type(selected) == "element") {
				selected.removeClass("tabItemSelected");
			}
			this.widget.addClass("tabItemSelected");
			inweo.execute(this.__select, this);
		}
	});
}